package cn.hfatec.shms.hr.hrEmployee.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.hr.hrEmployee.model.HrEmployee;
import cn.hfatec.shms.hr.hrEmployee.dao.HrEmployeeDao;
import cn.hfatec.shms.hr.hrEmployee.model.HrEmployeeParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("HrEmployeeService")
public class HrEmployeeService {

    public static final String BEAN_ID = "HrEmployeeService";

    //注入Dao层
    @Resource(name = "HrEmployeeDao")
    private HrEmployeeDao hrEmployeeDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param hrEmployeeParams
     * @param page
     *
     */
    @Transactional
    public Table queryHrEmployeeTable(HrEmployeeParams hrEmployeeParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", hrEmployeeParams);
        return baseDao.queryTableByPage("queryHrEmployee", params, page);
    }

    /**
     *
     * 插入数据
     * @param hrEmployee
     *
     */
    @Transactional
    public void saveHrEmployee(HrEmployee hrEmployee) {
        if(hrEmployee.getId() != null) {
            HrEmployee result = getHrEmployee(hrEmployee.getId());
            if(result != null) {
                hrEmployeeDao.update(hrEmployee);
            } else {
                hrEmployeeDao.insert(hrEmployee);
            }
        } else {
            hrEmployeeDao.insert(hrEmployee);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteHrEmployee(Integer id) {

        hrEmployeeDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param hrEmployeeList
     *
     */
    @Transactional
    public void deleteHrEmployeeBatch(List<String> hrEmployeeList) {
        for(String id : hrEmployeeList) {
            deleteHrEmployee(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public HrEmployee getHrEmployee(Integer id) {

        return hrEmployeeDao.getHrEmployeeById(id);
    }
    /**
     *
     * 根据ID获取数据
     * @param employeeId
     *
     */
    @Transactional
    public HrEmployee getHrEmployee(String employeeId) {

        return hrEmployeeDao.getEmployeeId(employeeId);
    }


}